<?php

namespace common\models\business;

use Yii;

/**
 * This is the model class for table "business_saleorder_detail".
 *
 * @property integer $id
 * @property integer $saleorderid
 * @property string $name
 * @property integer $pigid
 * @property string $weight
 * @property string $price
 */
class BusinessSaleorderDetail extends \yii\db\ActiveRecord
{


    //主要用于日志记录
    public $uselog = [
        'tabcomment' => '订购单详情',      //用于修改了什么的显示
        'mainfield' => 'id',      //主要的显示标题的字段
        'picturefield' => [],        //图片字段
        'timefield' => [],       //时间字段
        'unsetfiled' =>[],      //不需要记录的字段
    ];

    /**
     * @inheritdoc
     */
    public static function tableName()
    {
        return 'business_saleorder_detail';
    }

    /**
     * @inheritdoc
     */
    public function rules()
    {
        return [
            [['id'], 'required'],
            [['id', 'saleorderid', 'pigid'], 'integer'],
            [['weight', 'price'], 'number'],
            [['name'], 'string', 'max' => 255],
        ];
    }

    /**
     * @inheritdoc
     */
    public function attributeLabels()
    {
        return [
            'id' => 'ID',
            'saleorderid' => 'saleorderid',
            'name' => 'Name',
            'pigid' => 'Pigid',
            'weight' => 'Weight',
            'price' => 'Price',
        ];
    }


    /**
     * @return \yii\db\ActiveQuery
     * 获取所属的订单
     */
    public function getSale()
    {
        return $this->hasOne(BusinessSaleorder::className(),['id'=>'saleorderid']);
    }


    /**
     * @return \yii\db\ActiveQuery
     * 具体明细关联的仔猪
     */
    public function getPig()
    {
        return $this->hasOne(BusinessPig::className(),['id'=>'pigid']);
    }


}
